package com.muyu.common.product.remote.factory;

import com.muyu.common.product.domain.*;
import com.muyu.common.core.domain.Result;
import com.muyu.common.product.remote.ProductRemoteService;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品服务远程调用降级处理工厂
 *
 * @author JiaCheng
 * @version 1.0
 * @since 2025-09-21
 */
@Slf4j
@Component
public class ProductRemoteServiceFallbackFactory implements FallbackFactory<ProductRemoteService> {

    @Override
    public ProductRemoteService create(Throwable cause) {
        return new ProductRemoteService() {
            @Override
            public Result<ProductInfo> getProductInfo(Long productId) {
                log.error("获取商品信息失败，productId: {}, cause: {}", productId, cause.getMessage());
                return Result.error("获取商品信息失败");
            }

            @Override
            public Result<ProductSkuInfo> getSkuInfo(Long skuId) {
                log.error("获取SKU信息失败，skuId: {}, cause: {}", skuId, cause.getMessage());
                return Result.error("获取SKU信息失败");
            }

            @Override
            public Result<BrandInfo> getBrandInfo(Long brandId) {
                log.error("获取品牌信息失败，brandId: {}, cause: {}", brandId, cause.getMessage());
                return Result.error("获取品牌信息失败");
            }

            @Override
            public Result<CategoryInfo> getCategoryInfo(Long categoryId) {
                log.error("获取分类信息失败，categoryId: {}, cause: {}", categoryId, cause.getMessage());
                return Result.error("获取分类信息失败");
            }

            @Override
            public Result<List<ProductInfo>> getBatchProductInfo(List<Long> productIds) {
                log.error("批量获取商品信息失败，productIds: {}, cause: {}", productIds, cause.getMessage());
                return Result.error("批量获取商品信息失败");
            }

            @Override
            public Result<List<ProductSkuInfo>> getBatchSkuInfo(List<Long> skuIds) {
                log.error("批量获取SKU信息失败，skuIds: {}, cause: {}", skuIds, cause.getMessage());
                return Result.error("获取SKU信息失败");
            }

            @Override
            public Result<StockCheckResp> checkStock(StockCheckReq req) {
                log.error("检查库存失败，skuId: {}, quantity: {}, cause: {}", 
                         req.getSkuId(), req.getQuantity(), cause.getMessage());
                return Result.error("检查库存失败");
            }
        };
    }
}
